<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主子表提交')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <style>
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }

        input[type="number"] {
            -moz-appearance: textfield;

        }
        .file{
            margin-top: 20px;
            width: 167px;
        }
        .th-inner{
            width: 133px;
        }
        .pos{
            width: 305px;
        }
        .item button{
            width: 100px;
            height: 30px;
            color: #fff;
            background-color: skyblue;
            border-radius: 5px;
            border: none;
            outline: none;
            cursor: pointer;
        }
        .item input{
            display: none;
        }

    </style>


</head>


<body class="gray-bg">

<div class="main-content">
    <form id="form-add" class="form-horizontal">

        <input name="companyId" type="hidden" id="companyId"/>
        <input name="programId" type="hidden" id="programId"/>
        <input name="programName" type="hidden" id="programName"/>
        <input name="danId" type="hidden" id="danId"/>

        <h4 class="form-header h4">基本信息&nbsp;&nbsp;></h4>
        <!--工程内容、工程概述-->
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">工程内容：</label>
                    <div class="col-sm-8">
                        <textarea id="projectContent" name="projectContent" class="form-control" type="text" style="height: 90px"
                                  placeholder="高支模 深基坑等" required>[[${dan.projectContent}]]</textarea>
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">工程概述：</label>
                    <div class="col-sm-8">
                        <textarea id="note" name="note" class="form-control" type="text" style="height: 90px"
                                  placeholder="简述（超）危大工程内容、施工部位、重大危险源识别、现场施工条件、周边工况等" required>[[${dan.note}]]</textarea>
                    </div>
                </div>
            </div>
        </div>
        <!--规模-->
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">规模：</label>
                    <div class="col-sm-8">
                        <select id="scale" name="scale" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">危大</option>
                            <option value="2">超危大</option>
                        </select>

                    </div>
                </div>
            </div>
        </div>


        <span style="font-size: 15px;color: #6379bb">会审信息&nbsp;&nbsp;></span></br>
        <!--项目部-->
        <h4 class="form-header h4">项目部</h4>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审时间：</label>
                    <div class="col-sm-8">
                        <input id="jointTime" name="jointTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.jointTime}">
                    </div>
                </div>
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审状态：</label>
                    <div class="col-sm-8">
                        <select id="jointStatus" name="jointStatus" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">完成</option>
                            <option value="2">未完成</option>
                        </select>
                    </div>
                </div>

            </div>
        </div>

        <!--工程公司-->
        <h4 class="form-header h4">工程公司</h4>
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审时间：</label>
                    <div class="col-sm-8">
                        <input id="companyTime" name="companyTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.companyTime}">
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审状态：</label>
                    <div class="col-sm-8">
                        <select id="companyStatus" name="companyStatus" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">完成</option>
                            <option value="2">未完成</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>

        <!--集团-->
        <h4 class="form-header h4">集团</h4>
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审时间：</label>
                    <div class="col-sm-8">
                        <input id="gmassTime" name="gmassTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.gmassTime}">
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审状态：</label>
                    <div class="col-sm-8">
                        <select id="gmassStatus" name="gmassStatus" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">完成</option>
                            <option value="2">未完成</option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">会审附件：</label>
                    <div class="col-sm-8">
                        <input id="companyFiles" name="companyFiles" class="file" type="file"
                               accept='*'>
                    </div>
                </div>
            </div>
        </div>

        <!--专家论证-->
        <h4 class="form-header h4">专家论证</h4>
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">论证时间：</label>
                    <div class="col-sm-8">
                        <input id="masterTime" name="masterTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.masterTime}">
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">论证状态：</label>
                    <div class="col-sm-8">
                        <select id="masterStatus" name="masterStatus" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">有</option>
                            <option value="2">无</option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">论证附件：</label>
                    <div class="col-sm-8">
                        <input id="expertFiles" name="expertFiles" class="file" type="file" accept='*'>
                    </div>
                </div>
            </div>
        </div>

        <!--安全技术交底-->
        <h4 class="form-header h4">安全技术交底</h4>
        <div class="form-group">
            <div class="col-sm-12">

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">交底时间：</label>
                    <div class="col-sm-8">
                        <input id="discloseTime" name="discloseTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.discloseTime}">
                    </div>
                </div>

                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">交底状态：</label>
                    <div class="col-sm-8">
                        <select id="discloseStatus" name="discloseStatus" class="form-control noselect2">
                            <option value="0">请选择</option>
                            <option value="1">完成</option>
                            <option value="2">未完成</option>
                        </select>

                    </div>
                </div>

            </div>
        </div>


        <h4 class="form-header h4">施工信息&nbsp;&nbsp;></h4>
        <div class="form-group">
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <label class="col-sm-4 control-label">开始时间：</label>
                    <div class="col-sm-8">
                        <input id="startTime" name="startTime" class="form-control" type="text"
                               placeholder='yyyy-MM-dd' autocomplete='off' th:value="${dan.startTime}">
                    </div>
                </div>
            </div>
        </div>


    </form>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:src="@{/js/jquery.tmpl.js}"></script>

<script th:inline="javascript">

    /* 模块前缀url */
    var prefix = ctx + "danManage";

    /* 初始化 方法 */
    $(function () {
        var dan = [[${dan}]];
        $('#danId').val(dan.danId);
        $('#scale').val(dan.scaleName);
        $('#jointStatus').val(dan.jointStatusName);
        $('#companyStatus').val(dan.companyStatusName);
        $('#gmassStatus').val(dan.gmassStatusName);
        $('#masterStatus').val(dan.masterStatusName);
        $('#discloseStatus').val(dan.discloseStatusName);

        bindDatetimepicker();
    });

    /* 初始化 日期*/
    function bindDatetimepicker() {
        setTimeout(function () {
            $("#jointTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            $("#companyTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            $("#gmassTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            $("#masterTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            $("#discloseTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
            $("#startTime").datetimepicker({
                format: "yyyy-mm-dd",
                minView: "month",
                autoclose: true
            });
        }, 100)
    }

    // 危大工程校验
    function checkDangerFlag(){
        var projectContent = $("#projectContent").val();
        var note = $("#note").val();
        var scale = $("#scale option:selected").val();

        var jointTime = $("#jointTime").val();
        var jointStatus = $("#jointStatus option:selected").val();

        var companyTime = $("#companyTime").val();
        var companyStatus = $("#companyStatus option:selected").val();

        var gmassTime = $("#gmassTime").val();
        var gmassStatus = $("#gmassStatus option:selected").val();

        var discloseTime = $("#discloseTime").val();
        var discloseStatus = $("#discloseStatus option:selected").val();

        var startTime = $("#startTime").val();
        if(projectContent == null || projectContent == ''){
            return false;
        }
        if(scale == null || scale == ''){
            return false;
        }
        if(note == null || note == ''){
            return false;
        }
        if(jointTime == null || jointTime == ''){
            return false;
        }
        if(jointStatus == null || jointStatus == '' || jointStatus == '0'){
            return false;
        }
        if(companyTime == null || companyTime == ''){
            return false;
        }
        if(companyStatus == null || companyStatus == '' || companyStatus == '0'){
            return false;
        }
        if(gmassTime == null || gmassTime == ''){
            return false;
        }
        if(gmassStatus == null || gmassStatus == '' || gmassStatus == '0'){
            return false;
        }
        if(discloseTime == null || discloseTime == ''){
            return false;
        }
        if(discloseStatus == null || discloseStatus == '' || discloseStatus == '0'){
            return false;
        }
        if(startTime == null || startTime == ''){
            return false;
        }
        else{
            return true;
        }
    }

    // (超)危大工程校验
    function checkGreateDangerFlag(){
        var masterTime = $("#masterTime").val();
        var masterStatus = $("#masterStatus option:selected").val();
        if(masterTime == null || masterTime == ''){
            return false;
        }
        if(masterStatus == null || masterStatus == '' || masterStatus == '0'){
            return false;
        }
        else{
            return true;
        }
    }

    /* 主子表-提交 */
    function submitHandler() {

        var formData = new FormData();
        var scale = $("#scale option:selected").val();
        var startTime = $("#startTime").val();
        // 危大工程
        if(scale == "1" && (startTime != null && startTime != "")){
            // 保证预计施工开始时间有值的情况下,前面的值都应该有值(除了专家论证)
            if(!checkDangerFlag()){
                $.modal.alertWarning("请完善流程数据");
                return;
            }
        }

        // (超)危大工程
        if(scale == "2" && (startTime != null && startTime != "")){
            // 保证预计施工开始时间有值的情况下,前面的值都应该有值
            if(!checkDangerFlag() && !checkGreateDangerFlag()){
                $.modal.alertWarning("请完善流程数据");
                return;
            }
        }

        formData.append('projectContent', $("#projectContent").val());
        formData.append('scale', scale);
        formData.append('note', $("#note").val());
        formData.append('jointTime', $("#jointTime").val());
        formData.append('jointStatus', $("#jointStatus option:selected").val());

        formData.append('companyTime', $("#companyTime").val());
        formData.append('companyStatus', $("#companyStatus option:selected").val());
        formData.append('gmassTime', $("#gmassTime").val());
        formData.append('gmassStatus', $("#gmassStatus option:selected").val());

        formData.append('masterTime', $("#masterTime").val());
        formData.append('masterStatus', $("#masterStatus option:selected").val());

        formData.append('discloseTime', $("#discloseTime").val());
        formData.append('discloseStatus', $("#discloseStatus option:selected").val());

        formData.append('startTime', $("#startTime").val());
        formData.append('companyId', [[${companyId}]]);
        formData.append('programId', [[${programId}]]);
        formData.append('companyFile', $('#companyFiles')[0].files[0]);
        formData.append('expertFile', $('#expertFiles')[0].files[0]);
        formData.append('danId', $('#danId').val());
        $.ajax({
            url: prefix + "/updateDan",
            type: 'post',
            cache: false,       //上传文件不需要缓存
            data: formData,
            processData: false, //data值是FormData对象，不需要对数据进行处理
            contentType: false, //contentType值，因为是由<form>表单构造的FormData对象，且已经声明了属性enctype="multipart/form-data"，所以这里设置为false。
            dataType: "json",
            success: function (result) {
                $.operate.successCallback(result);
            }
        });
    }

</script>
</body>
</html>
</script>